import getWeekday from "./getWeekday";
import {formatWeatherData, getWeatherData} from "./weather";

async function greetings(isMorning: boolean, count: number,weatherApi?:string,city?:string) {
    const now = new Date();
    const weekday = getWeekday();
    let todayWeather = ""
    let tomorrowWeather = ""
    if (weatherApi && city) {
        const weatherData = await getWeatherData(city, weatherApi);
        if (weatherData) {
            const result = formatWeatherData(weatherData);
            todayWeather = result?.todayWeather ?? "";
            tomorrowWeather = result?.tomorrowWeather ?? "";
        }
    }
    const formattedDate = now.toLocaleDateString("zh-CN", {
        timeZone: "Asia/Shanghai",
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
    });
    const formattedTime = now.toLocaleTimeString("zh-CN", {
        timeZone: "Asia/Shanghai",
        hour: "2-digit",
        minute: "2-digit",
        second: "2-digit",
    });

    let reminderMessage = "";
    // 根据提醒次数设置不同的提醒内容
    if (count === 1) {
        reminderMessage = isMorning
            ? "别忘了【打卡】哦，开启元气满满的一天！☀️"
            : "工作辛苦啦，记得【打卡】结束一天的忙碌哦！🌙";
    } else if (count === 2) {
        reminderMessage = isMorning
            ? "别忘了【打卡】哦！开启元气满满的一天！☀️"
            : "工作辛苦啦，赶紧【打卡】收尾，放松一下吧！🌙";
    } else if (count === 3) {
        reminderMessage = isMorning
            ? "快行动！记得【打卡】开始一天的工作吧！☀️"
            : "工作辛苦啦，记得【打卡】结束一天的忙碌哦！🌙";
    } else if (count > 3) {
        reminderMessage = isMorning
            ? "这是最后一次提醒啦，记得【打卡】开始一天的工作吧！☀️"
            : "这是最后一次提醒啦，记得【打卡】结束一天的忙碌哦！🌙";
    }

    // 动态生成温馨提醒标题
    const reminderTitle =
        count === 1
            ? `✨ ****** 温馨提醒 ****** ✨`
            : `✨ ****** 温馨提醒【${count - 1}】 ****** ✨`;

    return `
${isMorning ? `🌞 ** 早上好！${weekday}！** 🌞` : `🌇 ** 晚上好！${weekday}！** 🌇`}

📅 今日日期：${formattedDate}  
⏰ 当前时间：${formattedTime}  

🌤 天气速报：
   📌 今天  ${todayWeather}
   📌 明天  ${tomorrowWeather}

${reminderTitle}
${reminderMessage}
`;
}

export default greetings;
